package com.mycode.composite09.resolve;

import java.util.ArrayList;
import java.util.List;

// 文件夹：容器组件
public class Folder extends AbstractFile{

    private String name;

    private List<AbstractFile> list = new ArrayList<>();

    public Folder(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile file) {
        list.add(file);
    }

    @Override
    public void remove(AbstractFile file) {
        list.remove(file);
    }

    @Override
    public AbstractFile getChild(int i) {
        return list.get(i);
    }

    @Override
    public void killVirus() {
        for (AbstractFile abstractFile : list) {
            abstractFile.killVirus();
        }
    }
}
